<!DOCTYPE html>
<html lang="en">
<head>
    <!-- Basic -->
    <meta charset="UTF-8" />

    <title>Dashboard | Nadhif - Responsive Admin Template</title>

    <link href="../public/static/css/bootstrap.min.css" rel="stylesheet">
	<link href="../public/static/css/plugins/bootstrap-table/bootstrap-table.min.css" rel="stylesheet">
	
	<script src="../public/static/js/jquery.min.js"></script>
    <script src="../public/static/js/bootstrap.min.js"></script>
    <script src="../public/static/js/plugins/bootstrap-table/bootstrap-table.min.js"></script>
    <script src="../public/static/js/plugins/bootstrap-table/bootstrap-table-zh-CN.min.js"></script>

</head>
<body>
<div class="col-md-offset-3 col-md-6">  
    <div class="panel panel-default">  
        <div class="panel-heading">  
            <h3 class="panel-title text-center">已添加教师账号</h3>  
        </div>  
        <div class="panel-body">  
            <div id="toolbar" class="btn-group">  
                <button id="btn_edit" type="button" class="btn btn-default" >
                    <span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>修改  
                </button>  
                <button id="btn_delete" type="button" class="btn btn-default">  
                    <span class="glyphicon glyphicon-remove" aria-hidden="true"></span>删除  
                </button>
                <button id="btn_insert" type="button" class="btn btn-default">
                    <span class="glyphicon glyphicon-remove" aria-hidden="true"></span>删除
                </button>
                <button id="button">测试</button>
            </div>  
            <table id="table" data-toggle="table" data-url="/scheduler/jobs" data-method="get"
                   data-query-params="queryParams"
                   data-toolbar="#toolbar"
                   data-pagination="true"
                   data-search="true"
                   data-show-refresh="true"
                   data-show-toggle="true"
                   data-show-columns="true"
                   data-page-number="1"
                   data-page-size="5"
                   data-page-list="[10, 25, 50, 100, All]"
                   data-click-to-select="true"
                   data-striped="true"
                   data-checkbox="true"

            >
                <thead>  
                <tr>
                    <th data-checkbox="true" data-maintain-selected="true" checkboxEnabled="true"></th>
                    <th data-field="id">用户账号</th>
                    <th data-field="jobId">用户密码</th>
                    <th data-field="jobName">教师姓名</th>
                </tr>  
                </thead>


            </table>  
        </div>  
    </div>  
</div>

<script>

    var $table = $('#table'),
        $button = $('#button');
        $btn_delete = $('#btn_delete');
        $btn_insert = $('#btn_insert');

    $(function () {
        $button.click(function () {
            alert('getSelections: ' + JSON.stringify($table.bootstrapTable('getSelections')));
        });
    });

    //删除
    $(function () {
        $btn_delete.click(function () {
            var ids = $.map($table.bootstrapTable('getSelections'), function (row) {
                deleteID=row.id;
                return row.id;
            });
			    $.ajax({
					type:"delete",
					url:"/scheduler/jobs/"+ deleteID,
					contentType: "application/json",
					success:function (msg) {
						console.log("删除成功");
						$("#table").bootstrapTable('refresh',{url:"/scheduler/jobs"});
					},error:function (){console.log("删除错误");}
				});
        });
    });
    //新增
    $(function () {
        $button.click(function () {
            $table.bootstrapTable('append', randomData());
            $table.bootstrapTable('scrollTo', 'bottom');
        });
    });

    function randomData() {
        var rows = [];

        for (var i = 0; i < 10; i++) {
            rows.push({
                id: startId + i,
                name: 'test' + (startId + i),
                price: '$' + (startId + i)
            });
        }
        return rows;
    }

    $(function () {
        $button.click(function () {
            var randomId = 100 + ~~(Math.random() * 100);
            $table.bootstrapTable('insertRow', {
                index: 1,
                row: {
                    id: randomId,
                    name: 'Item ' + randomId,
                    price: '$' + randomId
                }
            });
        });
    });
</script>
</body>

</html>